package com.ben.notebook.domain;

import com.ben.notebook.infrastructure.mapper.NoteMapper;
import org.springframework.stereotype.Service;

/**
 * 领域事件
 * 一个聚合根内的实体命令组合，只更新此domain包内相关数据，其他领域关联数据更新由api层调用
 * 领域模型的业务逻辑还是应该放在实体类方法中
 * @date 2021-05-03
 */
@Service
public class NoteCommands {

    private final NoteValidateService validateService;
    private final NoteMapper mapper;

    public NoteCommands(NoteValidateService validateService, NoteMapper mapper) {
        this.validateService = validateService;
        this.mapper = mapper;
    }

    public int update(Note note){
        validateService.validateUpdateNotNull(note);
        return note.update(mapper);
    }

    public int create(Note note) {
        validateService.validateCreateNotNull(note);
        return note.publish(mapper);
    }

    public int delete(Note note) {
        validateService.validateDeleteNotNull(note);
        return note.delete(mapper);
    }
}
